import { Controller, Get, Query } from '@nestjs/common';
import { AnalyticsService } from './analytics.service';
import { createResponse } from '../common/response.interface';
import type { IResponse } from '../common/response.interface';

@Controller('analytics')
export class AnalyticsController {
  constructor(private readonly analyticsService: AnalyticsService) {}

  @Get('cpu-trend')
  async getCpuTrend(
    @Query('servers') servers: string[] | string,
    @Query('startTime') startTime: string,
    @Query('endTime') endTime: string,
  ): Promise<IResponse<any>> {
    const serverNames = Array.isArray(servers) ? servers : servers.split(',');
    const trend = await this.analyticsService.getCpuTrend(
      serverNames,
      new Date(startTime),
      new Date(endTime),
    );
    return createResponse(trend);
  }
}